home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / endo / rotwindow.c < prev    next >
C/C++ Source or Header  |  1995-05-03  |  8KB  |  236 lines

  1. /*************************************************************************
  2.  *                                                                       *
  3.  *  Copyright (c) 1992, 1993 Ronald Joe Record                           *
  4.  *                                                                       *
  5.  *  All rights reserved. No part of this program or publication may be   *
  6.  *  reproduced, transmitted, transcribed, stored in a retrieval system,  *
  7.  *  or translated into any language or computer language, in any form or *
  8.  *  by any means, electronic, mechanical, magnetic, optical, chemical,   *
  9.  *  biological, or otherwise, without the prior written permission of:   *
  10.  *                                                                       *
  11.  *      Ronald Joe Record (408) 458-3718                                 *
  12.  *      212 Owen St., Santa Cruz, California 95062 USA                   *
  13.  *                                                                       *
  14.  *************************************************************************/
  15.  
  16. /*************************************************************************
  17.  *                                                                       *
  18.  *     Copyright (c) 1989...                  Hiram Clawson              *
  19.  *                                                                       *
  20.  *  All rights reserved. No part of this program or publication may be   *
  21.  *  reproduced, transmitted, transcribed, stored in a retrieval system,  *
  22.  *  or translated into any language or computer language, in any form or *
  23.  *  by any means, electronic, mechanical, magnetic, optical, chemical,   *
  24.  *  biological, or otherwise, without the prior written permission of:   *
  25.  *                                                                       *
  26.  *              Hiram Clawson                        (408) 429-5647      *
  27.  *              P. O. Box 3178, Santa Cruz, California 95063-3178 USA    *
  28.  *                                                                       *
  29.  *************************************************************************/
  30. /*************************************************************************
  31.  *        rotwindow.c: Rotate the viewing window                         *
  32.  *                                                                       *
  33.  *        Written by Hiram Clawson.                                      *
  34.  *        - 20 Mar 92 rr@sco.com (Ronald Joe Record)                     *
  35.  *          Ported to X11.                                               *
  36.  *        - 23 Mar 92 rr@sco.com (Ronald Joe Record)                     *
  37.  *          Added TranslateWindow(), SetWindow(), ScaleWindow(),         *
  38.  *          and TranslateView()                                          *
  39.  *************************************************************************/
  40. #include "globals.h"
  41.  
  42. static triple translated = {0.0};
  43.  
  44. void 
  45. RotateWindow( angle, RotVector )
  46. double *angle;    /*    in degrees    */
  47. triple *RotVector;
  48. {
  49. /*
  50.  *    Rotates the viewing window about the RotVector
  51.  */
  52.     triple rotated;
  53.     double theta;
  54.     double rotcos;
  55.     double rotsin;
  56.     double const1;
  57.     extern void TranslateWindow();
  58.  
  59.     theta = *angle;
  60.  
  61. /*    VECTOR_X_SCALAR(translated, translated, -1.0); */
  62. /*    TranslateWindow(translated); back before any translations */
  63.     rotcos = cos( theta * radians_per_degree );
  64.     rotsin = sin( theta * radians_per_degree );
  65.     const1 = 1.0 - rotcos;
  66.  
  67.     rotate ( (triple *) & window_center , & rotated, RotVector,
  68.                 & rotcos, & rotsin, & const1 );
  69.     window_center.x = rotated.x;
  70.     window_center.y = rotated.y;
  71.     window_center.z = rotated.z;
  72.     rotate ( (triple *) & window_top , & rotated, RotVector,
  73.                 & rotcos, & rotsin, & const1 );
  74.     window_top.x = rotated.x;
  75.     window_top.y = rotated.y;
  76.     window_top.z = rotated.z;
  77.     rotate ( (triple *) & window_upper_right , & rotated, RotVector,
  78.                 & rotcos, & rotsin, & const1 );
  79.     window_upper_right.x = rotated.x;
  80.     window_upper_right.y = rotated.y;
  81.     window_upper_right.z = rotated.z;
  82.     rotate ( (triple *) & window_right , & rotated, RotVector,
  83.                 & rotcos, & rotsin, & const1 );
  84.     window_right.x = rotated.x;
  85.     window_right.y = rotated.y;
  86.     window_right.z = rotated.z;
  87.     rotate ( (triple *) & view_point , & rotated, RotVector,
  88.                 & rotcos, & rotsin, & const1 );
  89.     view_point.x = rotated.x;
  90.     view_point.y = rotated.y;
  91.     view_point.z = rotated.z;
  92.  
  93.     view_point_constants();    /*    always call when window is changed */
  94.  
  95. /*    VECTOR_X_SCALAR(translated, translated, -1.0); */
  96. /*    TranslateWindow(translated); re-apply any translations */
  97.  
  98.     return;
  99. }
  100.  
  101. void SetWindow(axis)     /* Position the window on the x, y, or z axis */
  102. int axis;
  103. {
  104.     extern double window_distance;
  105.     extern triple window_center;
  106.  
  107.     if (axis == 1) { /* View window centered at (window_distance, 0, 0) */
  108.         window_center.x = window_distance;
  109.         window_center.y = 0.0;
  110.         window_center.z = 0.0;
  111.  
  112.         window_top.x = window_distance;
  113.         window_top.y = window_distance / 2.0;
  114.         window_top.z = 0.0;
  115.  
  116.         window_right.x = window_distance;
  117.         window_right.y = 0.0;
  118.         window_right.z = window_distance / 2.0;
  119.  
  120.         window_upper_right.x = window_distance;
  121.         window_upper_right.y = window_distance / 2.0;
  122.         window_upper_right.z = window_distance / 2.0;
  123.  
  124.         view_point.x = window_distance + 
  125.             (sqrt(window_distance / 2.0) / TAN_30_DEGREES);
  126.         view_point.y = 0.0;
  127.         view_point.z = 0.0;
  128.     }
  129.     else if (axis == 2) { /* Window centered at (0, window_distance, 0) */
  130.         window_center.y = window_distance;
  131.         window_center.x = 0.0;
  132.         window_center.z = 0.0;
  133.  
  134.         window_top.y = window_distance;
  135.         window_top.x = window_distance / 2.0;
  136.         window_top.z = 0.0;
  137.  
  138.         window_right.y = window_distance;
  139.         window_right.x = 0.0;
  140.         window_right.z = window_distance / 2.0;
  141.  
  142.         window_upper_right.y = window_distance;
  143.         window_upper_right.x = window_distance / 2.0;
  144.         window_upper_right.z = window_distance / 2.0;
  145.  
  146.         view_point.y = window_distance + 
  147.             (sqrt(window_distance / 2.0) / TAN_30_DEGREES);
  148.         view_point.x = 0.0;
  149.         view_point.z = 0.0;
  150.     }
  151.     else if (axis == 3) {    /* Window centered at (0, 0, window_distance) */
  152.         window_center.z = window_distance;
  153.         window_center.x = 0.0;
  154.         window_center.y = 0.0;
  155.  
  156.         window_top.z = window_distance;
  157.         window_top.y = window_distance / 2.0;
  158.         window_top.x = 0.0;
  159.  
  160.         window_right.z = window_distance;
  161.         window_right.y = 0.0;
  162.         window_right.x = window_distance / 2.0;
  163.  
  164.         window_upper_right.z = window_distance;
  165.         window_upper_right.x = window_distance / 2.0;
  166.         window_upper_right.y = window_distance / 2.0;
  167.  
  168.         view_point.z = window_distance + 
  169.             (sqrt(window_distance / 2.0) / TAN_30_DEGREES);
  170.         view_point.x = 0.0;
  171.         view_point.y = 0.0;
  172.     }
  173.     if ((axis == 1) || (axis == 2) || (axis == 3)) {
  174.         translated.x = translated.y = translated.z = 0.0;
  175.     }
  176.     view_point_constants();    /*    always call when window is changed */
  177. }
  178.  
  179. void 
  180. TranslateWindow( TransVector )
  181. triple TransVector;
  182. {
  183. /*
  184.  *    Translates the viewing window TransVector units
  185.  */
  186.     POINT_PLUS_VECTOR(window_center, window_center, TransVector);
  187.     POINT_PLUS_VECTOR(window_top, window_top, TransVector);
  188.     POINT_PLUS_VECTOR(window_upper_right, window_upper_right, TransVector);
  189.     POINT_PLUS_VECTOR(window_right, window_right, TransVector);
  190.     POINT_PLUS_VECTOR(view_point, view_point, TransVector);
  191.     POINT_PLUS_VECTOR(translated, translated, TransVector);
  192.  
  193.     view_point_constants();    /*    always call when window is changed */
  194.  
  195.     return;
  196. }
  197.  
  198. void 
  199. ScaleWindow(xscalar, yscalar)
  200. double xscalar, yscalar;
  201. {
  202. /*
  203.  *    Scales the viewing window by a factor of xscalar horizontally
  204.  *    and yscalar vertically. Window center and view point remain unchanged.
  205.  */
  206.     triple svec;
  207.  
  208.     VECTORIZE(svec, window_top, window_center);
  209.     VECTOR_X_SCALAR(svec, svec, yscalar);
  210.     POINT_PLUS_VECTOR(window_top, window_top, svec);
  211.     POINT_PLUS_VECTOR(window_upper_right, window_upper_right, svec);
  212.  
  213.     VECTORIZE(svec, window_right, window_center);
  214.     VECTOR_X_SCALAR(svec, svec, xscalar);
  215.     POINT_PLUS_VECTOR(window_right, window_right, svec);
  216.     POINT_PLUS_VECTOR(window_upper_right, window_upper_right, svec);
  217.  
  218.     view_point_constants();    /*    always call when window is changed */
  219.  
  220.     return;
  221. }
  222.  
  223. void 
  224. TranslateView( TransVector )
  225. triple TransVector;
  226. {
  227. /*
  228.  *    Translates the viewing point TransVector units
  229.  */
  230.     POINT_PLUS_VECTOR(view_point, view_point, TransVector);
  231.  
  232.     view_point_constants();    /*    always call when window is changed */
  233.  
  234.     return;
  235. }
  236.